package cn.yudao.ymcc.web.controller;

import cn.yudao.ymcc.dto.AlipayNotifyDto;
import cn.yudao.ymcc.service.IAlipayNotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Slf4j
@RestController
public class AliPayController {

    @Autowired
    private IAlipayNotifyService notifyService;

    /**
    * @Title: alipayNotify
    * @Description: 支付宝的回调
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/8/20 17:47
    * @Parameters:
    * @Return
    */
    //http://nhv7de.natappfree.cc/ymcc/pay/alipay/notify
    // http://nhv7de.natappfree.cc/ymcc/pay/ali/notify
    @PostMapping("/alipay/notify")
    public String alipayNotify(AlipayNotifyDto dto){
        try {
            log.info("回调回来了");
            String success =  notifyService.alipayNotify(dto);
            return success; // 如果返回的是“success”，支付宝就不会再次发送了
        }catch (Exception e){
            e.printStackTrace();
            return "error"; // 如果不是“success”，支付宝会使用最大努力通知--8次
        }
    }

    @PostMapping("/ali/notify")
    public String test(){
        return "1111111111111";
    }


}
